// 轮播图自动切换功能
const carouselChart = document.querySelector('.carousel-chart ul');
let currentIndex = 0;

function autoSlide() {
  currentIndex++;
  if (currentIndex >= carouselChart.children.length) {
    currentIndex = 0;
  }
  carouselChart.scrollTo({
    left: currentIndex * carouselChart.children[0].offsetWidth,
    behavior: 'smooth'
  });
}

setInterval(autoSlide, 3000); // 每3秒切换一次

// 商品购买按钮点击事件
const buyButtons = document.querySelectorAll('.product-item.buy');
buyButtons.forEach(button => {
  button.addEventListener('click', () => {
    const productName = button.closest('.product-item').dataset.productName;
    const price = button.closest('.product-item').dataset.price;
    console.log(`购买${productName}，价格为${price}`);
    // 这里可以添加实际的购买逻辑，如跳转到购物车页面或添加到购物车等操作
  });
});